<template>
    <el-cascader size="mini" 
                :options="list"
                :props="props"
                 separator="-"
                :value="value"
                @change="changeValue"> 

    </el-cascader>

</template>
<script>
import {getDepartment} from '@/api/department'
import {transListToTreeData} from '@/utils/index'
  export default {
    props:{
        value:{
            type: Number,
            default:null
        }
    },
    data(){
        return{
            //连及组件的集合
            list:[],
            props:{
                label: 'name',
                value: 'id' 
            }
        }
    },
    methods:{
        //部门树桩数据
        async getDepartment(){
            this.list = transListToTreeData(await getDepartment(),0)
        },
        //监听部门的数据
        changeValue(list){
            console.log(list)
            if(list.length > 0){
                this.$emit('input',list[list.length-1])
            }else{
                this.$emit('input',null)
            }
        }
    },
    created(){
        this.getDepartment()
    }

  }
</script>
